package com.haochang.chunkvod.controller.activity.cash;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.haochang.base.BaseActivity;
import com.haochang.base.BaseTextView;
import com.haochang.base.OnBaseClickListener;
import com.haochang.chunkvod.R;
import com.haochang.chunkvod.controller.adapter.cash.TakeOutAdapter;
import com.haochang.chunkvod.model.cash.GoodInfo;
import com.haochang.chunkvod.model.cash.TakeOutInfo;
import com.haochang.chunkvod.view.vod.popupWindow.VodPopWindow;
import com.haochang.chunkvod.view.vod.title.TitleView;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ImageView;

/**
 *@author qintao
 *created at 2016/11/7 12:49
 * 外卖
 */

public class TakeOutActivity extends BaseActivity
{
	private TitleView titleView;
	private ExpandableListView ex_listView;
	private TakeOutAdapter takeOutAdapter;
	private BaseTextView tv_totalPrice;
	private Button btn_checkOut;
	private List<TakeOutInfo> takeOutInfoList = new ArrayList<TakeOutInfo>();
	private HashMap<String, Boolean> stateHashMap = new HashMap<String, Boolean>();//用于记录每个RadioButton的状态，并保证只可选一个

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
	}

	@Override
	public void receiveParam()
	{

	}

	@Override
	public void initData()
	{
		TakeOutInfo takeOutInfo = new TakeOutInfo();
		takeOutInfo.setSerialNumber("45457878");
		takeOutInfo.setOrderTime("17:25");
		takeOutInfo.setTotalPrice(150);

		List<GoodInfo> list = new ArrayList<GoodInfo>();
		GoodInfo goodInfo = new GoodInfo();
		goodInfo.setGoodsName("水饺");
		goodInfo.setOrderNum(2);
		goodInfo.setUnit("份");
		goodInfo.setPrice(520);
		list.add(goodInfo);
		list.add(goodInfo);
		takeOutInfo.setGoodInfoList(list);

		takeOutInfoList.add(takeOutInfo);
		takeOutInfoList.add(takeOutInfo);
		takeOutInfoList.add(takeOutInfo);
	}

	@Override
	public void initViews()
	{
		setContentView(R.layout.activity_take_out);
		titleView = (TitleView) findViewById(R.id.titleView);
		titleView.setTitle("外卖列表").setTitleOnClickListener(new TitleView.ITitleOnClickListener()
		{
			@Override
			public void onBackClick()
			{
				finish();
			}

			@Override
			public void onDoneClick()
			{
				List<String> list = new ArrayList<String>();
				list.add("退出登录");
				int location[] = new int[2];
				ImageView img = (ImageView) titleView.findViewById(R.id.img_operates);
				img.getLocationOnScreen(location);
				int x = location[0];
				final VodPopWindow pop = new VodPopWindow(TakeOutActivity.this, list);
				pop.showPopupWindow(titleView, x);
				pop.setPopWindowListListener(new VodPopWindow.OnPopWindowListListener()
				{
					@Override
					public void onSelectItem(int position)
					{
						switch (position)
						{
						case 0:
							loginOut();
							break;
						default:
							break;
						}
					}
				});
			}
		});
		ex_listView = (ExpandableListView) findViewById(R.id.ex_listView);
		View view = LayoutInflater.from(context).inflate(R.layout.item_take_out_header, ex_listView, false);
		ex_listView.addHeaderView(view);
		for (int i = 0; i < takeOutInfoList.size(); i++)
		{
			stateHashMap.put(String.valueOf(i), false);
		}
		takeOutAdapter = new TakeOutAdapter(TakeOutActivity.this, ex_listView, takeOutInfoList, stateHashMap);
		ex_listView.setAdapter(takeOutAdapter);
		ex_listView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener()
		{
			@Override
			public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id)
			{
				return true;//返回true禁用ExpandableListView的整行点击事件
			}
		});
		tv_totalPrice = (BaseTextView) findViewById(R.id.tv_totalPrice);
		btn_checkOut = (Button) findViewById(R.id.btn_checkOut);
		btn_checkOut.setOnClickListener(onBaseClickListener);
	}

	private OnBaseClickListener onBaseClickListener = new OnBaseClickListener()
	{
		@Override
		public void onBaseClick(View v)
		{
			switch (v.getId())
			{
			case R.id.btn_checkOut:
				break;
			default:
				break;
			}
		}
	};
}
